﻿using WJSHWebApi.DBModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WJSHWebApi.DBModel;

namespace WJSHWebApi.Common
{
    public class SqlBuilder<T> where T : BaseDbmodel
    {
        public static readonly string FindSql = null;
        public static readonly string DeleteSql = null;
        public static readonly string FindAllSql = null;
        public static readonly string UpdateSql = null;

        static SqlBuilder()
        {
            Type type = typeof(T);
            FindSql = $"SELECT {string.Join(",", type.GetProperties().Select(a => $"[{a.Name}] ")) } FROM [{Extend.GetTableName<T>()}] where Id=@Id";

            DeleteSql = $"Delete from [{Extend.GetTableName<T>()}] where Id=@Id"; ;

            FindAllSql = $"SELECT {string.Join(",", type.GetProperties().Select(a => $"[{a.Name}] ")) } FROM [{Extend.GetTableName<T>()}]";

            UpdateSql = $"update [{type.Name}]  set {string.Join(",", type.GetProperties().Where(a => !a.Name.Equals("Id")).Select(a => $"[{a.Name}]=@ {a.Name}"))}  where Id =@Id";
        }
    }
}
